<?php
namespace Admin\Controller;
use Think\Controller;
Vendor('Filehuancun.Filehuancun');//Vendor 引入Filehuancun目录下的Filehuancun命名空间
Vendor('ExcleInOut.ExcleInOut');//Vendor 引入ExcleInOut目录下的ExcleInOut命名空间


class LsdlController extends Controller {
	public function deldir($path){
		// 如果是目录则继续
		if (is_dir ( $path )) {
			// 扫描一个文件夹内的所有文件夹和文件并返回数组
			$p = scandir ( $path );
			foreach ( $p as $val ) {
				// 排除目录中的.和..
				if ($val != "." && $val != "..") {
					// 如果是目录则递归子目录，继续操作
					if (is_dir ( $path . $val )) {
						// 子目录中操作删除文件夹和文件
						$this->deldir ( $path . $val . '/' );
						// 目录清空后删除空文件夹
						@rmdir ( $path . $val . '/' );
					} else {
						// 如果是文件直接删除
						unlink ( $path . $val );
					}
				}
			}
		}
	}
	 public function index() {
	 	switch($_POST["submit"])
	 	{
	 		case "查询" :
	 			{
	 				$user = M('cmxmkhmd');
	 				
	 				$sjkTemp=$user->select();//后期这里要按照条件筛选
	 				
	 				$arrTemp2 = array (); //输出可编辑信息
	 				
	 				for($ii = 0; $ii < count ( $sjkTemp ); $ii ++) {
	 					$arrTemp2 [$ii] [0] = $sjkTemp [$ii] [id];
	 					$arrTemp2 [$ii] [1] = $sjkTemp [$ii] [khmc];
	 					$arrTemp2 [$ii] [2] = $sjkTemp [$ii] [mdd];
	 					$arrTemp2 [$ii] [3] = $sjkTemp [$ii] [shr];
	 					$arrTemp2 [$ii] [4] = $sjkTemp [$ii] [shrdh];
	 					$arrTemp2 [$ii] [5] = $sjkTemp [$ii] [shdz];
	 					$arrTemp2 [$ii] [6] = $sjkTemp [$ii] [jd];
	 					$arrTemp2 [$ii] [7] = $sjkTemp [$ii] [wd];
	 				 					 	 					 				 	
	 				} 	 			
	 				$this->assign ( 'arr1', $arrTemp2 );	 					
	 				break;
	 			}
	 		
	 		default :
	 			{
	 				break;
	 			}
	 	}
	 	
	    $sess_auth = session('auth');
		if($sess_auth)
		{
		$this->assign('user',$sess_auth['user']);
		$this->display();//echo 输出和assign要在这个这个函数之前设置完成。
		}
	} 
	public function ajaxkhtj()
	{
		$user = M('cmxmkhmd');
		$data ['khmc']  = $_POST["khmc"];
		$data ['mdd']  = $_POST["mdd"];
		$data ['shr'] = $_POST["shr"];
		$data ['shrdh'] = $_POST["shrdh"];
		$data ['shdz'] = $_POST["shdz"];
		$data ['jd'] = $_POST["jd"];
		$data ['wd'] = $_POST["wd"];
		
		$data ['ddscz'] = $_POST["user"];		
		$today  =  date ( "Y-m-d H:i:s" );
		$data ['scrqsj'] = $today;
		
		$user->add ( $data );
	}
	public function ajaxsckh()
	{
		$temp2 = $_POST["arr2"];
		$temp2 = substr($temp2,0,strlen($temp2)-1);		
		$user = M('cmxmkhmd');
		$user->delete($temp2);//使用1,2,3这样的id字符串，删除数据库。
		
	}
	public function ajaxmdbjtj()
	{
		$temp1 = explode(',',$_POST["arr1"]);
		$temp2 = explode(',',$_POST["arr2"]);
		
		$user = M('cmxmkhmd');
	
		$j=0;
		for($i=0;$i<count($temp1);$i=$i+7)
		{
		
				$data['id'] = $temp2[$j];
				$data['khmc'] = $temp1[$i];
				$data['mdd'] = $temp1[$i+1];
				$data['shr'] = $temp1[$i+2];
				$data['shrdh'] = $temp1[$i+3];
				$data['shdz'] = $temp1[$i+4];				
				$data['jd'] = $temp1[$i+5];		
				$data['wd'] = $temp1[$i+6];
				$user->save($data);		
						
			    $j=$j+1;
		}
	}
	public function ceshi()//ajax测试方法
	{
		//$name1 ='ThinkPHP11111111111';
		//session('wwf',$name1);
		$sess_auth = session('auth');
		echo $sess_auth['per'];
	}
	/*查找字符、字符串第n次出现的位置
	 *@param string $str    原始字符串
	 *@param string $find需要查找的字符、字符串
	 *@param int    $n第几次出现的字符、字符串
	 *@return int   $count返回第n次出现的位置
	 */
	public function str_n_pos($str,$find,$n){
		for ($i=1;$i<=$n;$i++){
			$pos = strpos($str,$find);
			//echo "pos:".$pos.  "<br />\n" ;
			//这里加一是要把第一找到的在第二次查找避免掉
			$str = substr($str,$pos+1);
			//echo "pos jiequ:".$str.  "<br />\n" ;
			$pos_val=$pos+$pos_val+1;
		}
		//在这里重新减一，就是当前要查找的（第n个）字符的位置。
		$count = $pos_val-1;
		return $count;
	}
	
	
	
}

